<template>
  <BasicModal v-bind="$attrs" @register="registerCustomFieldModal" title="界面设置" @ok="handleSubmit" defaultFullscreen>
    <JVxeTable ref="tableRef" :columns="columns" :dataSource="dataSource"> </JVxeTable>
  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue';
import { JVxeTableInstance } from '/@/components/jeecg/JVxeTable/types';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { columns } from './dynamic.data';
import { saveOrUpdate } from './dynamic.api';
import { getCustomFields } from '/@/api/dynamic/';
let businessCode = ref<string>('');
let tableName = ref<string>('');
const [registerCustomFieldModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false });
  businessCode.value = data?.businessCode;
  tableName.value = data?.tableName;
  //console.log("businessCode:"+data?.businessCode,"tableName:",data?.tableName)
});
const isUpdate = ref(true);

const tableRef = ref<JVxeTableInstance>();
const dataSource = ref([]);


async function handleSubmit() {
  await saveOrUpdate(columns, isUpdate.value);
}

onMounted(() => {
  getCustomFields(businessCode.value, tableName.value).then((data) => {
    dataSource.value = data?.records;
  });
});
</script>
